package tech.aistar.day01.method;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(urlPatterns = "/users/loginView")
public class FormController extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //1. 设置文档的类型
        resp.setContentType("text/html;charset=utf-8");
        //2. 获取文档输出流
        PrintWriter out = resp.getWriter();
        //3. 输出内容到网页
        out.println("<!doctype html>");
        out.println("<html>");
        out.println("   <head>");
        out.println("       <meta charset='utf-8'>");
        out.println("       <title>用户登录</title>");
        out.println("   </head>");
        out.println("   <body>");
        //method默认是get方式
        //action指向的是后端的地址 - 项目上下文路径/映射路径
//        out.println("   <form action='/servlet/user/login' method='post'>");
        out.println("   <form action='/servlet/day01/get' method='post'>");
        out.println("       <input type='text' name='username'>");
        out.println("       <input type='password' name='password'>");
        out.println("       <input type='submit' value='login'>");
        out.println("   </form>");

        out.println("<a href='/servlet/user/login?username=lxn&password=111'>get请求</a>");

        out.println("   </body>");
        out.println("</html>");
    }
}
